package org.itzixi.adapter;

import jakarta.annotation.Resource;
import org.itzixi.config.MinIOConfig;
import org.itzixi.utils.MinIOUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
import java.util.List;


@Component("minio")
public class MinioStorageAdapter implements StorageAdapter{

    @Resource
    private MinIOConfig minIOConfig;

    @Override
    public void createBucket(String bucket) {

    }

    @Override
    public String uploadFile( String objectName, String fileName, boolean needUrl) throws Exception {
        return MinIOUtils.uploadFile(minIOConfig.getBucketName(), objectName, fileName, needUrl);
    }

    @Override
    public String uploadFile(String objectName, InputStream is, boolean needUrl) throws Exception {
        return MinIOUtils.uploadFile(minIOConfig.getBucketName(), objectName, is, true);

    }

    @Override
    public String uploadFileAndReturnUrl(MultipartFile multipartFile, String objectName) throws Exception {
        return MinIOUtils.uploadFile(minIOConfig.getBucketName(), objectName, multipartFile.getInputStream(), true);
    }

    @Override
    public void uploadFile(MultipartFile multipartFile, String objectName) throws Exception {
        MinIOUtils.uploadFile(minIOConfig.getBucketName(), objectName, multipartFile.getInputStream());
    }

    @Override
    public List<String> getAllBuckets() {
        return null;
    }

    @Override
    public InputStream download(String bucket, String objectName) {
        return null;
    }

    @Override
    public void deleteBucket(String bucket) {

    }

    @Override
    public void deleteObject(String bucket, String objectName) {

    }

    @Override
    public String getUrl(String objectName) {
        return minIOConfig.getFileHost() + "/" + minIOConfig.getBucketName() + "/" + objectName;
    }
}
